<!DOCTYPE html>  
<html lang="en">  
<head>  
    <meta charset="UTF-8">  
    <title></title>  
    <style type="text/css">
    	table{
    		margin: 5em auto;
    	}
    	th{
    	   width: 15em;
    	   height: 2em;
    	}
    	td{
    		height: 2em;
    	   width: 15em;
    	   text-align: center;
    	}
    </style>
</head >  
<body onload = "countTime()">  
    <div>
    	<table border="1" cellspacing="0" cellpadding="0">
    		<tr>
    			<th id="h1" colspan="4"><span>
    				距2021年还有
    			</span></th>
    		</tr>
    		<tr>
    			<th>天</th>
    			<th>时</th>
    			<th>分</th>
    			<th>秒</th>
    		</tr>
    		<tr>
    			<td> <span id="_d">00</span></td>
    			<td> <span id="_h">00</span></td>
    			<td> <span id="_m">00</span></td>
    			<td> <span id="_s">00</span></td>
    		</tr>
    	</table>
    </div>  
    
    <script type="text/javascript">  
        function countTime() { 
        	
            var date = new Date();  
            var now = date.getTime(); 
            
            var endDate = new Date("2021-1-1 00:00:00");  
            var end = endDate.getTime();  
            
            var leftTime = end-now;  
            
            var d,h,m,s;  
            if (leftTime>=0) {  
                d = Math.floor(leftTime/1000/60/60/24);  
                h = Math.floor(leftTime/1000/60/60%24);  
                m = Math.floor(leftTime/1000/60%60);  
                s = Math.floor(leftTime/1000%60);                     
            }  
            
            document.getElementById("_d").innerHTML = d+"天";  
            document.getElementById("_h").innerHTML = h+"时";  
            document.getElementById("_m").innerHTML = m+"分";  
            document.getElementById("_s").innerHTML = s+"秒";  

            console.log(d,h,m,s)
            setTimeout(countTime,1000);  
        }  
    </script>  
</body>  
</html>  